 public string CountStringOccurrences(string text, string pattern)
        {
            int count = 0;
            int i = 0;
            var sb = new StringBuilder();
            while ((i = text.IndexOf(pattern, i)) != -1)
            {
                i += pattern.Length;
                sb.AppendLine((i + 2).ToString());
                count++;
            }
            sb.Append(count.ToString());
            return sb.ToString();
        }

===========================================================================================================

                        if (Message.Contains("<IMG "))
                        {

                            string[] imgInfo = CountStringOccurrences(Message.Trim().ToLower(), "src").Split('\n');


                            var subData = new String[Convert.ToInt32(imgInfo[imgInfo.Length - 1])];


                            string[] imgPathArray = new string[subData.Length];

                            int imgCounter = 0;
                            String sbMailBody = string.Empty;

                            
                            for (int i = 0; i < imgPathArray.Length; i++)
                            {
                                int starPoint;
                                int endPoint;
                                string imagePath;
                                if (i == imgInfo.Length - 2)
                                {
                                    starPoint = Convert.ToInt32(imgInfo[i].Remove(imgInfo[i].Length - 1));
                                    endPoint = Message.Length;
                                    imagePath = GetImagePath(starPoint, endPoint);

                                   
                                    if (imagePath.Contains("file://"))
                                    {
                                        encodePath.Add(imagePath);
                                        Uri ur = new Uri(imagePath);
                                        imagePath = ur.LocalPath;
                                        decodePath.Add(imagePath);

                                    } 
                                    if (string.IsNullOrEmpty(imagePath) == false)
                                    {
                                        imgPathArray[imgCounter] = imagePath;
                                        imgCounter++;
                                    }
                                }
                                else
                                {
                                    starPoint = Convert.ToInt32(imgInfo[i].Remove(imgInfo[i].Length - 1));
                                    endPoint = Convert.ToInt32(imgInfo[i + 1].Remove(imgInfo[i + 1].Length - 1));
                                    imagePath = GetImagePath(starPoint, endPoint);

                                   
                                    if (imagePath.Contains("file://"))
                                    {
                                        encodePath.Add(imagePath);
                                        Uri ur = new Uri(imagePath);
                                        imagePath = ur.LocalPath;
                                        decodePath.Add(imagePath);
                                    }  

                                    if (string.IsNullOrEmpty(imagePath) == false)
                                    {
                                        imgPathArray[imgCounter] = imagePath;
                                        imgCounter++;
                                    }
                                }
                            }  


                           
                            


                           